package com.cdu.guoxinan.www.smartcom.controller;

import com.cdu.guoxinan.www.smartcom.domian.dto.PaymentDTO;
import com.cdu.guoxinan.www.smartcom.domian.dto.UserFeeQueryDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.Fee;
import com.cdu.guoxinan.www.smartcom.domian.vo.FeeStatisticsVO;
import com.cdu.guoxinan.www.smartcom.service.UserFeeService;
import com.cdu.guoxinan.www.smartcom.unit.model.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/userFee")
@Api(tags = "用户费用管理")
public class UserFeeController {
    
    @Resource
    private UserFeeService userFeeService;
    
    @GetMapping("/query")
    @ApiOperation("查询用户费用列表")
    public R queryUserFees(UserFeeQueryDTO queryDTO) {
        return userFeeService.queryUserFees(queryDTO);
    }
    
    @GetMapping("/statistics")
    @ApiOperation("获取用户费用统计")
    public R getUserFeeStatistics(@RequestParam Long userId) {
        FeeStatisticsVO statistics = userFeeService.getUserFeeStatistics(userId);
        return R.ok(statistics);
    }
    
    @PostMapping("/pay")
    @ApiOperation("缴费")
    public R payFee(@RequestBody PaymentDTO paymentDTO) {
        return userFeeService.payFee(paymentDTO);
    }
    
    @GetMapping("/getById")
    @ApiOperation("根据费用ID查询费用详情")
    public R getFeeById(@RequestParam Long feeId) {
        Fee fee = userFeeService.getFeeById(feeId);
        return fee != null ? R.ok(fee) : R.error("费用不存在");
    }
} 